package comics

import (
	"encoding/json"
	"io"
	"os"
)

//Loads JSON file from given path and uses ParseConfig on it
func GetComics(path string) (comics map[string]Comic, err error) {
	f, err := os.Open(path)
	if err != nil {
		return
	}
	return ParseConfig(f)
}

// Parses JSON config from the io.Reader 
// and returns it as a map of comic names to their structs
func ParseConfig(r io.Reader) (comics map[string]Comic, err error) {
	jsonDecoder := json.NewDecoder(r)
	comics = make(map[string]Comic)
	err = jsonDecoder.Decode(&comics)
	return
}
